<template>
<!--
  有些属性没有提示
-->
  <div >
    <el-table
      border
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="200">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
    </el-table>
<!--    分页-->
    <el-pagination
      background
      align="right"
      layout="prev, pager, next"
      :page-size="pageSize"
      :current-page="currentPage"
      :total="totals"
      @current-change="chang">
    </el-pagination>


  </div>
</template>

<script>

export default {
  name: 'Stu',
  data () {
    return {
      tableData: [],
      pageSize:5,
      currentPage:1,
      totals:0
    }
  },

  // 方法
  methods:{
    // 页码触发事件
    chang(current) {
      this.currentPage=current
      this.list() // 点击后面的页码需要重新刷新数据

    },
    // 列表展示
    list() { // 发送请求的拿到所有数据
      this.$http.post("/user/list", {"pageSize":this.pageSize, "currentPage":this.currentPage})
      .then(result=>{
        this.tableData=result.data.rows // 拿数据
        this.totals=result.data.totals // 获取总条数
      })
      .catch(reason => { // 处理异常
        alert("系统繁忙,请稍后再试!")
      })
    }
  },

  // 钩子函数
  mounted() {
    this.list()
  }
}
</script>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>

